;(function () {
	new Vue({
		el: '#rrat-flow',
		data: {
			menuList: [
				{name: '资源信息', disabled: true},
				{name: '流程信息', disabled: true},
			],
			tableSelected : '资源信息',
			bpm: {},
			flowNode: {},
			bpmList: [],
			queryParams: hlUrlUtil.$query(),
			isShowAdoptFlag: false,
			isShowAdoptText: '',
			isShowRefuseFlag: false,
			isShowRefuseText: '',
			resources:[],
			approveFlag:null
		},
		filters: {
		  formatUTCDate: function(time) {
		    return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd HH:mm:ss')
		  },
			formatDetailDate:function (time) {
				if (time === undefined) return '--'
				return hlDateUtil.formatUTCDate(time)
			},
		},
		computed: {
			buildingArea () {
				let res = 0;
				this.resources.map(item => {
					res += Number(item.buildingArea)
				})
				return res
			}
		},
		methods: {
			handleTabClick (res) {
				console.log(this.queryParams)
				this.tableSelected = res.name
				// if (res.name == '流程信息') this.getBpmDetailData()
			},
			// 获取资源信息
			getResources(){
				var that = this
				hlhttp.get({
			    url:'corpapi/sinoocean/bpm/project_resource_detail_list',
			    data:{
						'bpm_id':this.queryParams.bpmId
					},
			    success:function (data) {
			     that.resources = data
			    }
			  })
			},
			// 获取流程详情数据
			getBpmDetailData:function () {
			  var self = this;
			  hlhttp.get({
			    url:'bpm',
			    data:{
			      bpm_key:'RRAT',
			      bpm_id: this.queryParams.bpmId
			    },
			    success:function (data) {
			      var newArr = data;
			      var bpdefId = data.bpdefId || 0

						self.approveFlag = data.approveFlag
			      self.$set(self.$data, 'bpm', newArr)
			      self.getFlowNodeData(bpdefId)
			    }
			  })
			},
			// 获取流程节点数据
			getFlowNodeData:function (id) {
			  var self = this;
			  // 当所传id为0时展示最初始的业务节点图   ====>  开始 ----- 合同审核  ----- 结束
			  if(id === 0){
			    var nodeData = [{
			      name:'合同审核'
			    }]
			    self.flowNode = nodeData;

			  }
			  if(id !== 0){
			    hlhttp.get({
			      url:'bpdef_phases',
			      data:{'bpdef_id':id},
			      success:function(data){
			        self.flowNode = data
			      }
			    })
			  }
			},
			calculateTimeDifference:function(item1,item2){
			  return hlDateUtil.timeDifference(item1,item2)
			},
			// 获取工作流程任务列表数据
			getBpmListData:function () {
			  var self = this;
			  hlhttp.get({
			    url:'bpm/tasks',
			    data:{bpm_id: this.queryParams.bpmId},
			    success:function (data) {
			      var newArr = [];
			      for(var i = 0; i<data.length; i++){
			        if(data[i]['endTime'])newArr.push(data[i]);
			      }
			      self.$set(self.$data, 'bpmList', newArr)
			    }
			  })
			},

			//显示审核通过
			isShowAdopt () {
				this.isShowAdoptFlag = !this.isShowAdoptFlag
			},
			//显示审核拒绝
			isShowRefuse () {
				this.isShowRefuseFlag = !this.isShowRefuseFlag
			},
			//审批通过
			adopt () {
				hlhttp.put({
					url: 'bpm/_pass',
					data: {
						bpm_id: this.queryParams.bpmId,
						task_id: this.queryParams.taskId,
						memo: this.isShowAdoptText || '#',
						bpm_key: this.queryParams.bpmKey,
						state: '#'
					},
					success: (res) => {
						hlUrlUtil.goTo('todo', {projectIds: this.queryParams.projectIds, stateName: 'RRAT', ddtab: true})
					}
				})
			},
			//审批拒绝
			refuse () {
				hlhttp.put({
					url: 'bpm/_reject',
					data: {
						bpm_id: this.queryParams.bpmId,
						task_id: this.queryParams.taskId,
						memo: this.isShowRefuseText || '#',
						bpm_key: this.queryParams.bpmKey,
						state: '#'
					},
					success: (res) => {
						hlUrlUtil.goTo('todo', {projectIds: this.queryParams.projectIds, stateName: 'RRAT', ddtab: true})
					}
				})
			}
		},
		mounted () {
			this.getBpmDetailData()
			this.getResources()
			this.getBpmListData()
		}
	})
} ())
